// utils/request.ts
const baseUrl = 'http://localhost:3001/api'
type TMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
interface IRequestConfig {
  url: string
  data?: Object | {}
  method?: TMethod
  header?: Object
}

export function request(config: IRequestConfig) {
  wx.showLoading({
    title: '加载中'
  })
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + config.url,
      data: config.data || {},
      method: config.method || 'GET',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res: Object) {
        resolve(res)
      },
      fail() {
        reject()
      },
      complete() {
        wx.hideLoading()
      }
    })
  })
}